package zeno.project.springboot.controller.core;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import zeno.project.springboot.lucence.ChineseSearch;

import java.util.List;

/**
 * @author ZhiYong
 * @ClassName LuceneController.java
 * @Description 全文检索
 * @createTime 2021/04/18 15:23:00
 */
@Controller
@RequestMapping("/lucene")
public class LuceneController {

    @GetMapping("/test")
    public String test(Model model) {
        // 索引所在的目录
        String indexDir = "D:\\lucene2";
        // 要查询的字符
        String q = "上海繁华";
        try {
            List<String> list = ChineseSearch.search(indexDir, q);
            model.addAttribute("list", list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "lucene/result";
    }
}
